<template>
  <div class="mvs-container">
    <div class="outter">
      <div class="inner">
        <div class="filter-wrap">
          <div class="seciton-wrap">
            <span class="section-type">地区:</span>
            <ul class="tabs-wrap">
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: area == '全部' }"
                  @click="area = '全部'"
                  >全部</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: area == '内地' }"
                  @click="area = '内地'"
                  >内地</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: area == '港台' }"
                  @click="area = '港台'"
                  >港台</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: area == '欧美' }"
                  @click="area = '欧美'"
                  >欧美</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: area == '日本' }"
                  @click="area = '日本'"
                  >日本</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: area == '韩国' }"
                  @click="area = '韩国'"
                  >韩国</span
                >
              </li>
            </ul>
          </div>
          <div class="type-wrap">
            <span class="type-type">类型:</span>
            <ul class="tabs-wrap">
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: type == '全部' }"
                  @click="type = '全部'"
                  >全部</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: type == '官方版' }"
                  @click="type = '官方版'"
                  >官方版</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: type == '原声' }"
                  @click="type = '原声'"
                  >原声</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: type == '现场版' }"
                  @click="type = '现场版'"
                  >现场版</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: type == '网易出品' }"
                  @click="type = '网易出品'"
                  >网易出品</span
                >
              </li>
            </ul>
          </div>
          <div class="order-wrap">
            <span class="order-type">排序:</span>
            <ul class="tabs-wrap">
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: order == '上升最快' }"
                  @click="order = '上升最快'"
                  >上升最快</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: order == '最热' }"
                  @click="order = '最热'"
                  >最热</span
                >
              </li>
              <li class="tab">
                <span
                  class="title"
                  :class="{ active: order == '最新' }"
                  @click="order = '最新'"
                  >最新</span
                >
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <!-- mv容器 -->
    <!-- 推荐MV -->
    <div class="mvs">
      <my-scroll ref="mvScroll">
        <div class="outter">
          <div class="inner">
            <div class="items">
              <div
                class="item"
                @click="toMv(item.id)"
                v-for="(item, index) in mvs"
                :key="index"
              >
                <div class="img-wrap">
                  <img :src="item.cover" alt />
                  <div class="num-wrap">
                    <div class="iconfont icon-play"></div>
                    <div class="num">{{ item.playCount | count }}</div>
                  </div>
                  <div class="iconbox">
                    <span class="iconfont icon-play"></span>
                  </div>
                </div>
                <div class="info-wrap">
                  <div class="name">{{ item.name }}</div>
                  <div class="singer">{{ item.artistName }}</div>
                </div>
              </div>
            </div>
            <!-- 分页器 -->
            <div class="pagebox">
              <el-pagination
                @current-change="handleCurrentChange"
                background
                layout="prev, pager, next"
                :total="total"
                :current-page="page"
                :page-size="limit"
                :limit="limit"
                hide-on-single-page
              ></el-pagination>
            </div>
            <div class="more" @click="loadMore">
              查看更多
            </div>
          </div>
        </div>
      </my-scroll>
    </div>
  </div>
</template>

<script>
import { GetAllMv } from "../../api/music"
export default {
  name: "mvs",
  data() {
    return {
      type: "全部",
      area: "全部",
      order: "上升最快",
      // 总条数
      total: 0,
      // 页码
      page: 1,
      // 页容量
      limit: 30,
      mvs: [],
      ops: {
        //vuescroll的配置
        vuescroll: {
          sizeStrategy: "percent",
          detectResize: true,
        },
        scrollPanel: {
          scrollingX: false,
        },
        rail: {},
        bar: {
          showDelay: 500,
          onlyShowBarOnScroll: false,
          keepShow: true,
          background: "#b3c0d1",
          opacity: 1,
          hoverStyle: false,
          specifyBorderRadius: false,
          minSize: false,
          size: "6px",
          disable: false,
        },
      },
    }
  },
  created() {
    this.getMvs()
  },
  filters: {
    count(playcount) {
      if (playcount >= 10000) {
        playcount = Math.ceil(playcount / 10000) + "万"
      }
      return playcount
    },
  },
  watch: {
    type(newVal) {
      this.type = newVal
      this.page = 1
      this.getMvs()
      this.$refs.mvScroll.$refs.vs.scrollTo(
        {
          y: "0%",
        },
        0
      )
    },
    area(newVal) {
      this.area = newVal
      this.page = 1
      this.getMvs()
      this.$refs.mvScroll.$refs.vs.scrollTo(
        {
          y: "0%",
        },
        0
      )
    },
    order(newVal) {
      this.order = newVal
      this.page = 1
      this.getMvs()
      this.$refs.mvScroll.$refs.vs.scrollTo(
        {
          y: "0%",
        },
        0
      )
    },
  },
  methods: {
    toMv(id) {
      this.$router.push(`/musichome/videoinfo?id=${id}`)
    },
    handleCurrentChange(val) {
      this.page = val
      this.getMvs()
      this.$refs["vs"].scrollTo(
        {
          y: "0%",
        },
        0
      )
    },
    async getMvs() {
      let res = await GetAllMv({
        limit: this.limit,
        offset: (this.page - 1) * this.limit,
        area: this.area,
        order: this.order,
        type: this.type,
      })
      this.mvs = res.data
      if (res.count) {
        this.total = res.count
      }
    },
    // 移动端加载更多
    async loadMore() {
      this.page++
      let res = await GetAllMv({
        limit: this.limit,
        offset: (this.page - 1) * this.limit,
        area: this.area,
        order: this.order,
        type: this.type,
      })
      this.mvs.push(...res.data)
      if (res.count) {
        this.total = res.count
      }
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../../scss/common.scss";
@media (max-width: 600px) {
  .mvs-container {
    height: 100%;
  }
  li {
    list-style: none;
  }

  .mvs-container .filter-wrap {
    height: 110px;
    margin: 1.25rem 0.625rem;
  }

  .mvs-container .filter-wrap > div {
    margin-bottom: 30px;
    vertical-align: baseline;
    display: flex;
    align-items: center;
  }

  .mvs-container .filter-wrap > div span {
    font-size: 0.8rem;
    height: 100%;
  }

  .mvs-container .filter-wrap > div span.title {
    margin: 0.125rem;
    color: gray;
    cursor: pointer;
    padding: 0.3rem 0.625rem;
  }

  .mvs-container .filter-wrap > div span.title.active {
    color: $primary;
    background-color: $bg;
    border-radius: 20px;
  }

  .mvs-container .filter-wrap > div span.title::before {
    content: "", pos;
  }

  .mvs-container .filter-wrap > div ul {
    display: flex;
    flex-wrap: wrap;
  }

  .mvs-container .filter-wrap > div ul li:not(:last-child) {
    border-right: 1px solid #f2f2f1;
  }

  .mvs-container .mvs {
    margin: 0rem;
    height: calc(100% - 150px);
    position: relative;
  }

  .mvs-container .mvs .items {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
  }

  .mvs-container .mvs .items .item {
    width: 45%;
    cursor: pointer;
    margin-bottom: 30px;
  }

  .mvs-container .mvs .items .item .img-wrap {
    width: 100%;
    position: relative;
    .iconbox {
      position: absolute;
      top: 0px;
      left: 0px;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.6);
      color: rgb(98, 158, 218);
      display: flex;
      justify-content: center;
      align-items: center;
      opacity: 0;
      transition: 0.5s;
      span {
        color: rgb(98, 158, 218);
        width: 35px;
        height: 35px;
        background: rgba(255, 255, 255, 0.7);
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 50%;
      }
      span:hover {
        cursor: pointer;
      }
      span:before {
        transform: translateX(1px);
      }
    }
  }
  .mvs-container .mvs .items .item .img-wrap img {
    width: 100%;
    border-radius: 5px;
  }

  .mvs-container .mvs .items .item .img-wrap .num-wrap {
    position: absolute;
    color: white;
    top: 0;
    right: 0;
    display: flex;
    align-content: center;
    font-size: 15px;
    padding-right: 5px;
    padding-top: 2px;
  }

  .mvs-container .mvs .items .item .img-wrap .num-wrap .icon-play {
    font-size: 12px;
    display: flex;
    align-items: center;
    margin-right: 5px;
  }
  .items .item .img-wrap .num-wrap .icon-play {
    font-size: 12px;
    display: flex;
    align-items: center;
    margin-right: 5px;
  }

  .mvs-container .mvs .items .item .info-wrap .name {
    font-size: 15px;
    height: 25px;
    line-height: 25px;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mvs-container .mvs .items .item .info-wrap .singer {
    font-size: 14px;
    height: 20px;
    line-height: 20px;
    color: #c5c5c5;
  }
  .pagebox {
    display: none;
  }
  .more {
    width: 100%;
    text-align: center;
    display: block;
    line-height: 1rem;
    padding: 0.9rem 0rem;
    color: rgba(168, 168, 168, 0.8);
  }
}
@media (min-width: 600px) {
  .mvs-container {
    height: 100%;
  }
  li {
    list-style: none;
  }

  .mvs-container .filter-wrap {
    height: 110px;
    margin: 20px;
  }

  .mvs-container .filter-wrap > div {
    margin-bottom: 30px;
    vertical-align: baseline;
    display: flex;
    align-items: center;
  }

  .mvs-container .filter-wrap > div span {
    font-size: 14px;
    height: 100%;
  }

  .mvs-container .filter-wrap > div span.title {
    margin: 15px;
    color: gray;
    cursor: pointer;
    padding: 5px 20px;
  }

  .mvs-container .filter-wrap > div span.title.active {
    color: $primary;
    background-color: $bg;
    border-radius: 20px;
  }

  .mvs-container .filter-wrap > div span.title::before {
    content: "", pos;
  }

  .mvs-container .filter-wrap > div ul {
    display: flex;
  }

  .mvs-container .filter-wrap > div ul li:not(:last-child) {
    border-right: 1px solid #f2f2f1;
  }

  .mvs-container .mvs {
    margin: 0px 20px;
    height: calc(100% - 150px);
    position: relative;
  }

  .mvs-container .mvs .items {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .mvs-container .mvs .items .item {
    width: 250px;
    cursor: pointer;
    margin-right: 20px;
    margin-bottom: 30px;
  }

  .mvs-container .mvs .items .item .img-wrap {
    width: 100%;
    position: relative;
    .iconbox {
      position: absolute;
      top: 0px;
      left: 0px;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.6);
      color: rgb(98, 158, 218);
      display: flex;
      justify-content: center;
      align-items: center;
      opacity: 0;
      transition: 0.5s;
      span {
        color: rgb(98, 158, 218);
        width: 35px;
        height: 35px;
        background: rgba(255, 255, 255, 0.7);
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 50%;
      }
      span:hover {
        cursor: pointer;
      }
      span:before {
        transform: translateX(1px);
      }
    }
  }
  .mvs-container .mvs .items .item .img-wrap:hover .iconbox {
    opacity: 1;
  }
  .mvs-container .mvs .items .item .img-wrap img {
    width: 100%;
    border-radius: 5px;
  }

  .mvs-container .mvs .items .item .img-wrap .num-wrap {
    position: absolute;
    color: white;
    top: 0;
    right: 0;
    display: flex;
    align-content: center;
    font-size: 15px;
    padding-right: 5px;
    padding-top: 2px;
  }

  .mvs-container .mvs .items .item .img-wrap .num-wrap .icon-play {
    font-size: 12px;
    display: flex;
    align-items: center;
    margin-right: 5px;
  }
  .items .item .img-wrap .num-wrap .icon-play {
    font-size: 12px;
    display: flex;
    align-items: center;
    margin-right: 5px;
  }

  .mvs-container .mvs .items .item .info-wrap .name {
    font-size: 15px;
    height: 25px;
    line-height: 25px;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mvs-container .mvs .items .item .info-wrap .singer {
    font-size: 14px;
    height: 20px;
    line-height: 20px;
    color: #c5c5c5;
  }
  .pagebox {
    display: flex;
    width: 100%;
    height: 60px;
    justify-content: center;
    align-items: center;
  }
  .more {
    display: none;
  }
  .outter {
    width: 100%;
    display: flex;
    justify-content: center;
    .inner {
      width: 100%;
      max-width: 1200px;
    }
  }
}
</style>
